﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the GNU General Public License version 2 (GPLv2).
// See accompanying file License.txt or copy at http://phuse.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Phuse.Net.Nntp
{
    using System.Diagnostics.CodeAnalysis;

    /// <summary>Enumerates the standard statuses a newsgroup can have, see
    /// <a href="http://www.ietf.org/rfc/rfc3977.txt">RFC 3977</a> 7.6.3.</summary>
    public enum GroupStatus
    {
        /// <summary>Equivalent to the standard "y".</summary>
        PostingPermitted,

        /// <summary>Equivalent to the standard "n".</summary>
        PostingNotPermitted,

        /// <summary>Equivalent to the standard "m".</summary>
        PostingModerated,

        /// <summary>The status field had a non-standard value.</summary>
        Unknown
    }

    /// <summary>Encapsulates the information about an active newsgroup.</summary>
    /// <threadsafety static="true" instance="false"/>
    public sealed class ActiveGroupInfo
    {
        private readonly string groupName;
        private readonly long highWaterMark;
        private readonly long lowWaterMark;
        private readonly GroupStatus groupStatus;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>Gets the name of the newsgroup.</summary>
        public string GroupName
        {
            get { return this.groupName; }
        }

        /// <summary>Gets the reported high water mark.</summary>
        [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "WaterMark", Justification = "This is not a watermark.")]
        public long HighWaterMark
        {
            get { return this.highWaterMark; }
        }

        /// <summary>Gets the reported low water mark.</summary>
        [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "WaterMark", Justification = "This is not a watermark.")]
        public long LowWaterMark
        {
            get { return this.lowWaterMark; }
        }

        /// <summary>Gets the current status of the group.</summary>
        public GroupStatus GroupStatus
        {
            get { return this.groupStatus; }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal ActiveGroupInfo(string groupName, long highWaterMark, long lowWaterMark, string groupStatus)
        {
            this.groupName = groupName;
            this.highWaterMark = highWaterMark;
            this.lowWaterMark = lowWaterMark;

            switch (groupStatus)
            {
                case "y":
                    this.groupStatus = GroupStatus.PostingPermitted;
                    break;
                case "n":
                    this.groupStatus = GroupStatus.PostingNotPermitted;
                    break;
                case "m":
                    this.groupStatus = GroupStatus.PostingModerated;
                    break;
                default:
                    this.groupStatus = GroupStatus.Unknown;
                    break;
            }
        }
    }
}
